<template>
	<view>
		<view class="cu-form-group">
			<view class="title">标题</view>
			<input class="text" placeholder="请输入标题" v-model="form.title"></input>
		</view>

		<view class="cu-form-group align-start">
			<view class="title">内容</view>
			<textarea maxlength="-1" v-model="form.content" placeholder="请输入内容"></textarea>
		</view>

		<view class="cu-form-group align-start">
			<view class="title">平台回复</view>
			<textarea maxlength="-1" v-model="form.reply"></textarea>
		</view>

		<!-- <view class="padding flex flex-direction">
			<button class="cu-btn bg-yellow lg" @tap="submit">提交</button>
		</view> -->


	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex';
	import uQRCode from '@/common/uqrcode.js'
	export default {
		data() {
			return {
				imgList: [],
				form: {
					title: '',
					content: '',
					reply:''
				}

			}
		},
		onLoad(data) {
			this.$http.post('Message.detail', {
				id: data.id
			}).then(res => {
				this.form = res.data;
			})
		},
		onShow() {

		},
		onNavigationBarButtonTap(e) {
			if (e.index == 0) {
				uni.navigateTo({
					url: `/pages/user/msglist`
				})
			}
		},
		methods: {
			get_object_first(data) {
				for (var key in data)
					return data[key];
			},
			ChooseImage() {
				uni.chooseImage({
					count: 4, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {

						uni.uploadFile({
							url: this.$host + '/api/common/upload',
							filePath: res.tempFilePaths[0],
							name: 'file',
							formData: {},
							success: (re) => {
								let rr = JSON.parse(re.data)
								console.log(rr)
								if (rr.code) {
									this.imgList.push(res.tempFilePaths[0]);
									this.form.payimage = rr.data.url;
								}
							},
							error: function(res) {
								console.log(res)
							}
						});
					}
				});
			},
			ViewImage(e) {
				uni.previewImage({
					urls: this.imgList,
					current: e.currentTarget.dataset.url
				});
			},
			DelImg(e) {
				uni.showModal({
					title: '温馨提示',
					content: '确定要删除吗？',
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							this.imgList.splice(e.currentTarget.dataset.index, 1);
							this.form.payimage = '';
						}
					}
				})
			},
			submit() {
				this.$http.post('Message.add', this.form).then(res => {
					this.$api.msg(`提交成功`);
					// this.getUserPayment()
					setTimeout(() => {
						this.$api.prePage()
					}, 800)
				})
			}
		}
	}
</script>

<style>

</style>
